package com.cpa.admin.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhen.zhao01
 * @CreateDate 2018/11/4
 */
@Slf4j
public class DateConverter implements Converter<String, Date> {
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    @Override
    public Date convert(String source) {
        if (StringUtils.isEmpty(source)) {
            return null;
        }


        try {
            return simpleDateFormat.parse(source);
        } catch (ParseException e) {
            log.error("时间转换失败: " + source);
            e.printStackTrace();

        }
        return null;
    }
}
